<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>身体指数BMI检测</h2>
<form action="">
    <input type="text" name="height" placeholder="身高(米)">
    <input type="text" name="weight" placeholder="体重(公斤)">
    <input type="button" value="开始检测" onclick="fn()">
</form>
<h1>检测结果:</h1>
<!--引入axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    function fn() {
        //得到form表单中的数据
        let data = new FormData(document.querySelector("form"));
        //发出异步请求 如果需要用到FormData使用post请求否则get请求
        axios.post("/bmi",data).then(function (response) {
            //得到h1
            let h1 = document.querySelector("h1");
            h1.innerText="检测结果:"+response.data;
        })
    }
</script>

</body>
</html>